home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Font Fun / GradientText / GradientText.cs next >
Encoding:
Text File  |  2001-01-15  |  1.2 KB  |  37 lines

  1. //-------------------------------------------
  2. // GradientText.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class GradientText: FontMenuForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new GradientText());
  14.      }
  15.      public GradientText()
  16.      {
  17.           Text = "Gradient Text";
  18.           Width *= 3;
  19.           strText = "Gradient";
  20.           font = new Font("Times New Roman", 144, FontStyle.Italic);
  21.      }
  22.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  23.      {
  24.           SizeF  sizef  = grfx.MeasureString(strText, font);
  25.           PointF ptf    = new PointF((cx - sizef.Width) / 2,
  26.                                      (cy - sizef.Height) / 2);
  27.  
  28.           RectangleF rectf = new RectangleF(ptf, sizef);
  29.  
  30.           LinearGradientBrush lgbrush = new LinearGradientBrush(rectf, 
  31.                                         Color.White, Color.Black, 
  32.                                         LinearGradientMode.ForwardDiagonal);
  33.           grfx.Clear(Color.Gray);
  34.           grfx.DrawString(strText, font, lgbrush, ptf);
  35.      }
  36. }
  37.